package com.babyqiao.wallpaper.manager.utils.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * @author qinglongzhai
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Value("${local.image.uploaddic}")
    private String imageDic;
//    @Override
//    /*
//     * 解决跨域访问
//     * */
//    public void  addCorsMappings(CorsRegistry registry){
//        registry.addMapping("/**")
//                //.allowedOriginPatterns("*")
//                .allowedOrigins("*")
//                .allowedMethods("*")
//                .allowedHeaders("*")
//                .allowCredentials(true);
//    }

    /**
     * 地址转换
     *
     * @Author qinglongZhai
     * @Date 2020/12/9
     * * @param registry:
     * * @return: void
     */

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //注意前面要加file,不然是访问不了的
        registry.addResourceHandler("/image/**").addResourceLocations("file:" + imageDic);

    }

}
